
var DomianTableResData = [];


// 表格渲染
// 域名表格渲染
function domainNameTable(page, mDomain) {
    PostAjaxData(`/api/Index/GetDomainByAccountCodeDomainLimit?mDomain=${mDomain || ""}&page=${page}&limit=10`)
        .then(res => {
            // console.log(res, "domainNameTableRES")

            DomianTableResData = res.data
            //表格内容渲染
            domainNameTableRender(res)

            //单选框点击事件
            domainNameCheck();

            //删除点击事件
            DomainTableDelete()

            //详情点击事件
            DomainTableDetail()

            //添加点击事件
            DomainTableAdd()

            //分页渲染事件
            DomainPaging(res.allcount)
            // DomainPaging(res.allcount)
            
            //邮箱点击事件
            DomainEmailTdClick()
        })
        .catch(err => {
            console.log(err)
        })
}

//域名 分页
function DomainPaging(count) {
    var laypage = layui.laypage;
    laypage.render({
        elem: 'demo-laypage-domain',
        limit: 10,
        count: count, // 数据总数
        jump: function (obj, first) {
            if (!first) {
                $("#domainCheckAll")[0].checked = false
                console.log(obj.curr)
                let mDomainName = document.querySelector("#mDomain").value
                PostAjaxData(`/api/Index/GetDomainByAccountCodeDomainLimit?mDomain=${mDomainName || ""}&page=${obj.curr}&limit=10`)
                .then(res=>{
                    console.log(res)
                    //表格内容渲染
                    domainNameTableRender(res)

                    //单选框点击事件
                    domainNameCheck();

                    //删除点击事件
                    DomainTableDelete()

                    //详情点击事件
                    DomainTableDetail()

                    //添加点击事件
                    DomainTableAdd()
                })
                .catch(err=>{
                    console.log(err)
                })
            }
        }
    });
}

//根据序号 产生 img图标
function DomainIndexToImg(arr){
    let ImgInnerHtml = "";
    for (let i = 0; i < arr.length; i++) {
        if(arr[i] == "5"){
            ImgInnerHtml+=`<img src="./img/icon/1.svg" alt="">`
        }
        else if(arr[i] == "6"){
            ImgInnerHtml+=`<img src="./img/icon/2.svg" alt="">`
        }
        else if(arr[i] == "7"){
            ImgInnerHtml+=`<img src="./img/icon/3.svg" alt="">`
        }
        else if(arr[i] == "8"){
            ImgInnerHtml+=`<img src="./img/icon/7.svg" alt="">`
        }
        else if(arr[i] == "9"){
            ImgInnerHtml+=`<img src="./img/icon/6.svg" alt="">`
        }
        else if(arr[i] == "10"){
            ImgInnerHtml+=`<img src="./img/icon/4.svg" alt="">`
        }
        else if(arr[i] == "11"){
            ImgInnerHtml+=`<img src="./img/icon/5.svg" alt="">`
        }
    }
    return ImgInnerHtml

}


//页面渲染
function domainNameTableRender(res) {
    let DomainNametable_body = document.querySelector(".DomainNametable_body")
    DomainNametable_body.innerHTML = "";
    for (let i = 0; i < res.data.length; i++) {
        //最大的tr
        let newTr = document.createElement("tr")

        //单选框
        let newTd = document.createElement("td")
        let newinput = document.createElement("input")
        newinput.type = "checkbox"
        newinput.className = "domianCheck"
        newTd.appendChild(newinput)
        newTr.appendChild(newTd)



        // 域名
        let newDomain = document.createElement("td")

        let DomainContactWareHouseList = res.data[i].DomainContactWareHouseList

        // console.log(DomainContactWareHouseList,"域名")
        let DomainArr = [];
        for (let j = 0; j < DomainContactWareHouseList.length; j++) {
            if(!DomainArr.includes(DomainContactWareHouseList[j].ContactType)){
                DomainArr.push(DomainContactWareHouseList[j].ContactType)
            }
        }
        newDomain.innerHTML = `<div><div style="margin-bottom:10px">${res.data[i].Domain}</div>${DomainIndexToImg(DomainArr)}</div>`
        
        // console.log(DomainArr)
        newDomain.classList.add("Domainleft")
        newTr.appendChild(newDomain)
        // 域名






        

        // //邮箱   
        let newEmail = document.createElement("td")
        let EmailValue = "";
        if (res.data[i].DomainContactWareHouseList.length > 0) {
        for (let j = 0; j < res.data[i].DomainContactWareHouseList.length; j++) {
            // console.log(res.data[i].DomainContactWareHouseList[j].ContactValue)
                 EmailValue+=res.data[i].DomainContactWareHouseList[j].ContactValue+"\n"
            }
        };
        newEmail.innerHTML = `<div class="overflowFlag">${EmailValue}</div>`
        newTr.appendChild(newEmail)

        // //电话   
        let newPhone = document.createElement("td")
        newPhone.textContent = ""
        newTr.appendChild(newPhone)

        // //备注
        let newTrip = document.createElement("td")
        newTrip.textContent = res.data[i].Trip
        newTr.appendChild(newTrip)



        // //操作
        let newOperate = document.createElement("td")

        let DomainNameContactValueImg = document.createElement("img")
        DomainNameContactValueImg.src = "./img/dec.svg"
        DomainNameContactValueImg.classList.add("ContactValue")
        newOperate.appendChild(DomainNameContactValueImg)

        let DomainNameAddDomainNameImg = document.createElement("img")
        DomainNameAddDomainNameImg.src = "./img/add.svg"
        DomainNameAddDomainNameImg.classList.add("AddDomainName")
        newOperate.appendChild(DomainNameAddDomainNameImg)


        let DomainNamedelDomainNameImg = document.createElement("img")
        DomainNamedelDomainNameImg.src = "./img/del.svg"
        DomainNamedelDomainNameImg.classList.add("delDomainName")
        newOperate.appendChild(DomainNamedelDomainNameImg)


        newTr.appendChild(newOperate)


        DomainNametable_body.appendChild(newTr)
    }
}



// 域名 查询点击事件
$("#secectDomainBtn").click(function () {
    let mDomain = $("#mDomain").val()
    domainNameTable(1, mDomain)
})


//域名全选 反选
$("#domainCheckAll").click(function () {

    let domainCheckOnce = document.querySelectorAll(".DomainNametable_body>tr>td>.domianCheck")
    for (let i = 0; i < domainCheckOnce.length; i++) {
        domainCheckOnce[i].checked = $("#domainCheckAll")[0].checked
    }
})

//域名单选框
function domainNameCheck() {
    let domainCheckOnce = document.querySelectorAll(".DomainNametable_body>tr>td>.domianCheck")
    for (let i = 0; i < domainCheckOnce.length; i++) {
        domainCheckOnce[i].onclick = function () {
            // if (domainCheckOnce[i].checked) {
            //如果点击的是true

            for (let j = 0; j < domainCheckOnce.length; j++) {
                if (domainCheckOnce[j].checked == false) {
                    $("#domainCheckAll")[0].checked = false
                    break;
                } else {
                    $("#domainCheckAll")[0].checked = true
                }
            }
        }
    }
}


//域名邮箱单个td 点击 弹出框

function DomainEmailTdClick(){
    let DomainEmailTr = document.querySelectorAll(".DomainNametable_body>tr")
    for (let i = 0; i < DomainEmailTr.length; i++) {
        DomainEmailTr[i].querySelectorAll("td")[2].onclick = function(){
            layer.open({
                type: 1, // page 层类型
                area:["500px","300px"],
                title: '信息',
                shade: 0.6, // 遮罩透明度
                shadeClose: true, // 点击遮罩区域，关闭弹层
                anim: 0, // 0-6 的动画形式，-1 不开启
                content: `<div style="padding: 50px;font-size:20px">${DomainEmailTr[i].querySelectorAll("td")[2].innerText}</div>`
              });
        }
    }
}

//域名导出    导出全部
$("#daochuAllWebsite").click(function () {
    let domainCheckOnce = document.querySelectorAll(".DomainNametable_body>tr>td>.domianCheck")
    let domainCheckOnceArr = [];

    for (let i = 0; i < domainCheckOnce.length; i++) {
        if (domainCheckOnce[i].checked == true) {
            domainCheckOnceArr.push(DomianTableResData[i])
        }
    }
    // console.log(domainCheckOnceArr)
    // console.log(DomianTableResData,"选中的数据")

    if (domainCheckOnceArr.length > 0) {
       
        let data = DomainExportSelectAllData(domainCheckOnceArr)
        // console.log(data)
        //导出选中的数据

        let ExportCsvFileName = "域名列表-"+GetNowTime()+".csv"
        ExportToCSV(data, ExportCsvFileName)

        layer.msg("导出数据")

    } else {
        layer.msg("请选择需要导出的数据")
    }
})

// 导出选中的域名
function DomainExportSelectAllData(domainCheckOnceArr){
    let AllData = [];
    let dataTitle = ["域名","公司名称","Email",'FaceBook','Twitter','Linkedin',"Youtube",'Instagram','Pinterest','Skype','地址',"电话","传真"]
    AllData.push(dataTitle)
    
    for (let i = 0; i < domainCheckOnceArr.length; i++) {
        let DomainName = domainCheckOnceArr[i].Domain 
        let CompanyName = "";
        let Email = "";
        let FaceBook = "";
        let Twitter = "";
        let Linkedin = "";
        let Youtube= "";
        let Instagram = "";
        let Pinterest = "";
        let Skype = "";
        let Address = "";
        let Phone = ""
        let Fax = ""

       for (let j = 0; j < domainCheckOnceArr[i].DomainContactWareHouseList.length; j++) {
            if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 0){

                Email += domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue

            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 1){
                
                Phone+= domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue

            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 2){
             
                Fax = domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue

            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 3){

                Address+=domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue
                
            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 4){

                CompanyName+=domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue

            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 5){

                FaceBook+=domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue

            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 6){

                Twitter+=domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue

            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 7){
                
                Linkedin+=domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue

            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 8){
                
                Skype+=domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue

            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 9){
                
                Youtube+=domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue

            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 10){

                Instagram+=domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue
                
            }else if(domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactType == 11){

                Pinterest+=domainCheckOnceArr[i].DomainContactWareHouseList[j].ContactValue
            }
       }

       let dataOnce = [DomainName,CompanyName,Email,FaceBook,Twitter,Linkedin,Youtube,Instagram,Pinterest,Skype,Address,Phone,Fax];

       AllData.push(dataOnce)
    }
    return AllData
}





//域名导出    导出邮箱
$("#daochuWebsiteEmail").click(function () {
    // console.log("导出邮箱")

    let domainCheckOnce = document.querySelectorAll(".DomainNametable_body>tr>td>.domianCheck")

    let domainCheckOnceArr = [];

    for (let i = 0; i < domainCheckOnce.length; i++) {
        if (domainCheckOnce[i].checked == true) {
            domainCheckOnceArr.push(i)
        }
    }
    if (domainCheckOnceArr.length > 0) {
        let EmailArr = [];
        for (let i = 0; i < domainCheckOnceArr.length; i++) {
            EmailArr.push(document.querySelectorAll(".DomainNametable_body>tr")[i].querySelectorAll("td")[2].innerText)
        }
        let EmailText = EmailArr.join("\r\n")
        // console.log(EmailText)

        let DomainTxtName = "邮箱"+GetNowTime()+".txt"
        ExportToTXT(DomainTxtName, EmailText)

    } else {
        layer.msg("请选择需要导出的数据")
    }

})



// 域名删除点击事件

function DomainTableDelete() {
    let domaintr = document.querySelectorAll(".DomainNametable_body>tr")
    for (let i = 0; i < domaintr.length; i++) {
        domaintr[i].querySelectorAll("td")[5].querySelector(".delDomainName").onclick = function () {

            let mId = DomianTableResData[i].Id

            //删除
            PostAjaxData(`/api/Index/DelDomainByAccountCodeId?mId=${mId}`)
                .then(res => {
                    // console.log(res.msg)
                    domainNameTable(1)
                    layer.msg(res.msg)

                })
                .catch(err => {
                    console.log(err)
                })

                //刷新
                refresh()
        }
    }
}


//域名 添加点击事件
function DomainTableAdd() {

    let domaintr = document.querySelectorAll(".DomainNametable_body>tr")
    for (let i = 0; i < domaintr.length; i++) {
        domaintr[i].querySelectorAll("td")[5].querySelector(".AddDomainName").onclick = function () {

            let domainName = document.querySelectorAll(".DomainNametable_body>tr")[i].querySelectorAll("td")[1].innerText
            // disabled
            $("#addBox").show()
            $("#Domain").val(domainName)
            $("#Domain")[0].setAttribute('disabled', 'disabled')
        }
    }
}


//域名 详情点击事件 
function DomainTableDetail() {
    let domaintr = document.querySelectorAll(".DomainNametable_body>tr")
    for (let i = 0; i < domaintr.length; i++) {
        domaintr[i].querySelectorAll("td")[5].querySelector(".ContactValue").onclick = function () {
            //获取mid
            // 先 获取吧 
            //根据域名

            // let mId = DomianTableResData[i].DomainContactWareHouseList[0].DomainId
            // console.log(mId)

            let domainName = domaintr[i].querySelectorAll("td")[1].innerText
            // console.log(domainName)

            if (!$(this).hasClass("tabactive")) {
                $(this).addClass("tabactive")
                $(".website").removeClass("tabactive")
            }
            $(".detail_title_bg").css({
                left: "50%"
            })
            $(".website_detail").hide()
            $(".history_detail").show()

            $(".history>img")[0].src = './img/restore_active.svg';
            $(".website>img")[0].src = './img/horizontal.svg';

            let data = {
                Domain: domainName,
            }

            // console.log(data)
            contactMethodTable(1, data)

        }
    }
}







var ContactTableResData = [];
//联系方式表格渲染
contactMethodTable(1)
function contactMethodTable(page, data) {
    PostAjaxData(`/api/Index/QueryHistoryByAccountCodeLimit?page=${page}&limit=10`, data || "")
        .then(res => {
            ContactTableResData = res.data

            //表格渲染
            contactMethodRender(res)

            //联系的单选框
            contactCheck();

            //联系的删除点击事件
            contactDeleteClick()

            //联系的编辑点击事件
            contactEditClick();

            //分页渲染事件
            contactMethodPaging(res.allcount)
           
            //数据内容点击事件
            contactEmailTdClick()
        })
        .catch(err => {
            console.log(err)
        })
}

//数据内容点击事件
function contactEmailTdClick(){
    let contactEmailTr = document.querySelectorAll(".contactMethodtable_body>tr")
    for (let i = 0; i < contactEmailTr.length; i++) {
        contactEmailTr[i].querySelectorAll("td")[2].onclick = function(){
            layer.open({
                type: 1, // page 层类型
                // area:["500px","300px"],
                title: '信息',
                shade: 0.6, // 遮罩透明度
                shadeClose: true, // 点击遮罩区域，关闭弹层
                anim: 0, // 0-6 的动画形式，-1 不开启
                content: `<div style="padding: 50px;font-size:20px">${contactEmailTr[i].querySelectorAll("td")[2].innerText}</div>`
              });
        }
    }
}


//联系方式查询点击事件

$("#selectHistoryBtn").click(function () {
    let StartTime = $("#StartTime").val()
    let EndTime = $("#EndTime").val()
    let Domain = $("#DomainSelect").val()
    let ContactValue = $("#ContactValueSelect").val()
    let ContactType = $("#ContactTypeSelect").val()

    let data = {
        StartTime: StartTime,
        EndTime: EndTime,
        Domain: Domain,
        ContactValue: ContactValue,
        ContactType: ContactType
    }
    contactMethodTable(1, data)
    // console.log("联系方式查询点击事件")

})

//数据类型转化选择类型
function ContactTypeToSelectType(ContactType){
    let SelectType;
if(ContactType == 0){
    SelectType = "邮箱"
}else if(ContactType == 1){
    SelectType = "电话"
    
}else if(ContactType == 2){
    SelectType = "传真"
    
}else if(ContactType == 3){
    SelectType = "地址"
    
}else if(ContactType == 4){
    SelectType = "公司名称"
    
}else if(ContactType == 5){
    SelectType = "Facebook"
    
}else if(ContactType == 6){
    SelectType = "Twitter"
    
}else if(ContactType == 7){
    SelectType = "Linkedin"
    
}else if(ContactType == 8){
    SelectType = "Skype"
    
}else if(ContactType == 9){
    SelectType = "Youtube"
    
}else if(ContactType == 10){
    SelectType = "Instagram"
    
}else if(ContactType == 11){
    SelectType = "Pinterest"
    
}
return SelectType
}

//表格渲染
function contactMethodRender(res) {
    let contactMethodtable_body = document.querySelector(".contactMethodtable_body")
    contactMethodtable_body.innerHTML = "";
    for (let i = 0; i < res.data.length; i++) {
        let newTr = document.createElement("tr")

        let checkTd = document.createElement("td")
        let newinput = document.createElement("input")
        newinput.type = "checkbox"
        newinput.className = "contactCheck"
        checkTd.appendChild(newinput)
        newTr.appendChild(checkTd)


        let SourceUrlTd = document.createElement("td")
        SourceUrlTd.textContent = res.data[i].SourceUrl
        newTr.appendChild(SourceUrlTd)


        //数据内容
        let dataContentTd = document.createElement("td")
        dataContentTd.innerHTML = `<div class="overflowFlag">${res.data[i].ContactValue}</div>`
        newTr.appendChild(dataContentTd)

        //数据类型
        let dataTypeTd = document.createElement("td")
        let dataType = ContactTypeToSelectType(res.data[i].ContactType);
        dataTypeTd.textContent = dataType
        newTr.appendChild(dataTypeTd)

        // //备注
        let TripTd = document.createElement("td")
        TripTd.textContent = res.data[i].Trip
        newTr.appendChild(TripTd)




        // //操作
        let newOperate = document.createElement("td")

        let ContactValueImg = document.createElement("img")
        ContactValueImg.src = "./img/edit.svg"
        ContactValueImg.className = "EditContactValue"
        newOperate.appendChild(ContactValueImg)

        let AddDomainNameImg = document.createElement("img")
        AddDomainNameImg.src = "./img/del.svg"
        AddDomainNameImg.className = "DeleteContactValue"
        newOperate.appendChild(AddDomainNameImg)
        newTr.appendChild(newOperate)



        contactMethodtable_body.appendChild(newTr)
    }
}


// contactMethodPaging(res.allcount)

//联系方式表格  分页渲染
function contactMethodPaging(count) {
    let StartTime = $("#StartTime").val()
    let EndTime = $("#EndTime").val()
    let Domain = $("#DomainSelect").val()
    let ContactValue = $("#ContactValueSelect").val()
    let ContactType = $("#ContactTypeSelect").val()

    let data = {
        StartTime: StartTime,
        EndTime: EndTime,
        Domain: Domain,
        ContactValue: ContactValue,
        ContactType: ContactType
    }
    var laypage = layui.laypage;
    laypage.render({
        elem: 'demo-laypage-contactmethod',
        limit: 10,
        count: count, // 数据总数
        jump: function (obj, first) {
            if (!first) {
                $("#contactCheckAll")[0].checked = false
                // contactMethodTable(obj.curr)
                PostAjaxData(`/api/Index/QueryHistoryByAccountCodeLimit?page=${obj.curr}&limit=10`, data || "")
                .then(res=>{
                     //表格渲染
                    contactMethodRender(res)

                    //联系的单选框
                    contactCheck();

                    //联系的删除点击事件
                    contactDeleteClick()

                    //联系的编辑点击事件
                    contactEditClick();

                })
                .catch(err=>{
                    console.log(err)
                })
            }
        }
    });
    
}


//全选
$("#contactCheckAll").click(function () {
    let contactCheckAll = $("#contactCheckAll")[0].checked
    let checkOnceInput = document.querySelectorAll(".contactCheck")
    for (let i = 0; i < checkOnceInput.length; i++) {
        checkOnceInput[i].checked = contactCheckAll
    }
})


//反选
function contactCheck() {
    let contactCheckOnce = document.querySelectorAll(".contactCheck")
    for (let i = 0; i < contactCheckOnce.length; i++) {
        contactCheckOnce[i].onclick = function () {
            for (let j = 0; j < contactCheckOnce.length; j++) {

                if (contactCheckOnce[j].checked == false) {
                    $("#contactCheckAll")[0].checked = false;
                    break;
                }
                else {
                    $("#contactCheckAll")[0].checked = true;
                }
            }
        }
    }
}

//联系方式删除点击事件
function contactDeleteClick() {
    let DeleteContactValue = document.querySelectorAll(".DeleteContactValue")
    for (let i = 0; i < DeleteContactValue.length; i++) {
        DeleteContactValue[i].onclick = function () {

            let mId = ContactTableResData[i].Id
            PostAjaxData(`/api/Index/DelHistoryByAccountCodeId?mId=${mId}`)
                .then(res => {
                    // console.log(res)
                    layer.msg(res.msg)
                    contactMethodTable(1)
                })
                .catch(err => {
                    console.log(err)
                })
                refresh()

        }
    }
}

var ExitObject;
//联系方式编辑 点击事件
function contactEditClick() {
    let EditContactValue = document.querySelectorAll(".EditContactValue")
    for (let i = 0; i < EditContactValue.length; i++) {
        EditContactValue[i].onclick = function () {
            $("#addBox").show()

            let domain = document.querySelectorAll(".contactMethodtable_body>tr")[i].querySelectorAll("td")[1].innerText
            let content = document.querySelectorAll(".contactMethodtable_body>tr")[i].querySelectorAll("td")[2].innerText
            let Datatype = document.querySelectorAll(".contactMethodtable_body>tr")[i].querySelectorAll("td")[3].innerText
            let trip = document.querySelectorAll(".contactMethodtable_body>tr")[i].querySelectorAll("td")[4].innerText

            $("#Domain").val(domain)

            let radioTypeItem = document.querySelectorAll(".radio_item");
            for (let j = 0; j < radioTypeItem.length; j++) {

                radioTypeItem[j].querySelector("img").src = "./img/radio.svg"

                if (radioTypeItem[j].querySelector("span").innerText == Datatype) {
                    radioTypeItem[j].querySelector("img").src = "./img/radio_active.svg"
                }
            }

            $("#ContactValue").val(content)
            $("#Trip").val(trip)

            $("#Domain")[0].setAttribute('disabled', 'disabled')
            ExitObject = ContactTableResData[i]

            $(".affirmAdd").html("修改")
        }
    }
}




// 联系方式   导出全部
$("#daochuAllHistory").click(function () {

    let contactCheckOnce = document.querySelectorAll(".contactMethodtable_body>tr>td>.contactCheck")
    let contactCheckOnceArr = [];

    for (let i = 0; i < contactCheckOnce.length; i++) {
        if (contactCheckOnce[i].checked == true) {
            contactCheckOnceArr.push(i)
        }
    }


    if (contactCheckOnceArr.length > 0) {
        let AllData = [];
        let dataTitle = ["来源", "数据内容", "数据类型", "备注"];
        AllData.push(dataTitle)

        for (let i = 0; i < ContactTableResData.length; i++) {
            let data = [
                ContactTableResData[i].SourceUrl,
                ContactTableResData[i].ContactValue,
                ContactTableResData[i].SourceType,
                ContactTableResData[i].Trip
            ]
            AllData.push(data)
        }
        let ExportCsvFileName = "联系方式-"+GetNowTime()+".csv"
        ExportToCSV(AllData, ExportCsvFileName)
    } else {
        layer.msg("请选择需要导出的数据")
    }

})

function GetNowTime(){
    let now = new Date();
    let year = now.getFullYear();
    let month = now.getMonth() + 1;
    let day = now.getDate();
    let hours = now.getHours();
    let minutes = now.getMinutes();
    let seconds = now.getSeconds();
    return `${year}-${month}-${day} ${hours}.${minutes}.${seconds}`
}


//联系方式  导出txt
$("#daochuHistoryEmail").click(function () {
    let domainCheckOnce = document.querySelectorAll(".contactMethodtable_body>tr>td>.contactCheck")
    let domainCheckOnceArr = [];

    for (let i = 0; i < domainCheckOnce.length; i++) {
        if (domainCheckOnce[i].checked == true) {
            domainCheckOnceArr.push(ContactTableResData[i].ContactValue)
        }
    }
    if (domainCheckOnceArr.length > 0) {


        let ExportEmailName ="邮箱-"+GetNowTime()+".txt"
        ExportToTXT(ExportEmailName, domainCheckOnceArr.join("\r\n"))

    } else {
        layer.msg("请选择需要导出的数据")
    }
})


//域名导出csv文件格式
function ExportToCSV(data, filename) {
    // 转换数据为CSV格式
    const csvContent = data.map(row => row.join(",")).join("\n");

    // 创建Blob对象
    const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });

    // 创建并触发下载
    const link = document.createElement("a");
    if (link.download !== undefined) { // 支持下载属性
        const url = URL.createObjectURL(blob);
        link.setAttribute("href", url);
        link.setAttribute("download", filename);
        link.style.visibility = 'hidden';
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    }
}

// 使用示例
// const data = [
//     ["Name", "Age", "City"],
//     ["Alice", "24", "New York"],
//     ["Bob", "30", "San Francisco"]
// ];

// exportToCSV(data, "example.csv");

//域名导出txt文件格式
function ExportToTXT(filename, text) {
    var blob = new Blob([text], { type: 'text/plain' });

    var url = URL.createObjectURL(blob);

    var a = document.createElement('a');

    a.href = url;
    a.download = filename;

    document.body.appendChild(a);
    a.click();

    document.body.removeChild(a);
    URL.revokeObjectURL(url);
}







// //域名上一页
// document.querySelector(".DomainNameList_box>.paging>.prev").onclick = function () {
//     //判断当前是否为1 为1 就不管

//     // 如果不是一  那就获取当前的下表
//     let index = document.querySelector(".DomainNameList_box>.paging>.pagingnum>.DomainNameList_boxpageclick").innerText
//     if (index != 1) {
//         document.querySelectorAll(".DomainNameList_box>.paging>.pagingnum>div")[index - 1].classList.remove("DomainNameList_boxpageclick")
//         document.querySelectorAll(".DomainNameList_box>.paging>.pagingnum>div")[index - 2].classList.add("DomainNameList_boxpageclick")

//         let page = document.querySelector(".DomainNameList_box>.paging>.pagingnum>.DomainNameList_boxpageclick").innerText

//         domainNameTable(page)
//     }

// }

// // 域名下一页
// document.querySelector(".DomainNameList_box>.paging>.next").onclick = function () {
//     console.log(document.querySelector(".DomainNameList_box>.paging>.next").innerHTML)
//     //获取当前选中页
//     let index = document.querySelector(".DomainNameList_box>.paging>.pagingnum>.DomainNameList_boxpageclick").innerText
//     //获取最后一页是多少
//     let lastindex = document.querySelectorAll(".DomainNameList_box>.paging>.pagingnum>div")

//     if (index != lastindex.length) {
//         document.querySelectorAll(".DomainNameList_box>.paging>.pagingnum>div")[index - 1].classList.remove("DomainNameList_boxpageclick")
//         document.querySelectorAll(".DomainNameList_box>.paging>.pagingnum>div")[index].classList.add("DomainNameList_boxpageclick")
//     }
//     let page = document.querySelectorAll(".DomainNameList_box>.paging>.pagingnum>.DomainNameList_boxpageclick")[0].innerText
//     console.log(page)

//     //重新渲染
//     domainNameTable(page)

// }

// // 域名 分页点击事件   域名列表
// function DomainNameListPageClick() {
//     let DomainNameListPage = document.querySelectorAll(".DomainNameList_box>.paging>.pagingnum>div")
//     for (let i = 0; i < DomainNameListPage.length; i++) {
//         DomainNameListPage[i].onclick = function () {
//             for (let j = 0; j < DomainNameListPage.length; j++) {
//                 DomainNameListPage[j].classList.remove("DomainNameList_boxpageclick")
//                 $("#domainCheckAll")[0].checked = false
//             }
//             DomainNameListPage[i].classList.add("DomainNameList_boxpageclick")

//             domainNameTable(i + 1)
//         }
//     }
// }

// //域名表格  分页渲染
// function domainNamePaging(num, pagenumber) {
//     let domainNamePage = document.querySelector(".DomainNameList_box>.paging>.pagingnum")
//     domainNamePage.innerHTML = ""
//     if (num > 10) {
//         let pageNum = Math.ceil(num / 10);
//         for (let i = 1; i < pageNum + 1; i++) {
//             let page = document.createElement("div")
//             if (i == pagenumber) {
//                 page.classList.add("DomainNameList_boxpageclick")
//             }
//             page.textContent = i
//             domainNamePage.appendChild(page)
//         }
//     } else {
//         let page = document.createElement("div")
//         page.textContent = 1
//         page.classList.add("DomainNameList_boxpageclick")
//         domainNamePage.appendChild(page)
//     }

//     DomainNameListPageClick()
// }



// //联系方式分页点击事件
// function contactMethodPageClick() {
//     let contactMethodPage = document.querySelectorAll(".contactMethod_box>.paging>.pagingnum>div")
//     for (let i = 0; i < contactMethodPage.length; i++) {
//         contactMethodPage[i].onclick = function () {
//             for (let j = 0; j < contactMethodPage.length; j++) {
//                 contactMethodPage[j].classList.remove("contactMethod_boxpageclick")
//                 $("#contactCheckAll")[0].checked = false
//             }
//             contactMethodPage[i].classList.add("contactMethod_boxpageclick")
//             contactMethodTable(i + 1)
//         }
//     }

// }





// //联系方式上一页
// document.querySelector(".contactMethod_box>.paging>.prev").onclick = function () {
//     console.log(document.querySelector(".contactMethod_box>.paging>.prev").innerHTML)

//     let index = document.querySelector(".contactMethod_box>.paging>.pagingnum>.contactMethod_boxpageclick").innerHTML
//     if (index != 1) {
//         console.log(index)
//         document.querySelectorAll(".contactMethod_box>.paging>.pagingnum>div")[index - 1].classList.remove("contactMethod_boxpageclick")
//         document.querySelectorAll(".contactMethod_box>.paging>.pagingnum>div")[index - 2].classList.add("contactMethod_boxpageclick")
//         contactMethodTable(index - 1)
//     }
// }


// //联系方式下一页

// document.querySelector(".contactMethod_box>.paging>.next").onclick = function () {

//     let index = document.querySelector(".contactMethod_box>.paging>.pagingnum>.contactMethod_boxpageclick").innerText
//     //获取最后一页是多少
//     let lastindex = document.querySelectorAll(".contactMethod_box>.paging>.pagingnum>div")
//     console.log(index, lastindex)

//     if (index != lastindex.length) {
//         document.querySelectorAll(".contactMethod_box>.paging>.pagingnum>div")[index - 1].classList.remove("contactMethod_boxpageclick")
//         document.querySelectorAll(".contactMethod_box>.paging>.pagingnum>div")[index].classList.add("contactMethod_boxpageclick")
//         console.log(parseInt(index) + 1)
//         contactMethodTable(parseInt(index) + 1)
//     }
// }



// function contactMethodPaging(){
//     // if (num < 10) {
//         //     let page = document.createElement("div")
//         //     page.textContent = 1
//         //     page.classList.add("contactMethod_boxpageclick")
//         //     contactMethodPage.appendChild(page)
    
//         // } else {
//         //     let contactMethodPage = document.querySelector(".contactMethod_box>.paging>.pagingnum")
//         //     contactMethodPage.innerHTML = "";
//         //     let pageNum = Math.ceil(num / 10);
//         //     for (let i = 1; i < pageNum + 1; i++) {
//         //         let page = document.createElement("div")
//         //         if (i == 1) {
//         //             page.classList.add("contactMethod_boxpageclick")
//         //         }
//         //         page.textContent = i
//         //         contactMethodPage.appendChild(page)
//         //     }
//         // }
    
//         // contactMethodPageClick()
//     }
    